package com.A01.sys.service.impl;

import com.A01.sys.entity.UserEntity;
import com.A01.sys.service.UserService;
import com.A01.utils.ContextHolderUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.A01.utils.PageUtils;
import com.A01.utils.Query;

import com.A01.sys.dao.UserRecruitDao;
import com.A01.sys.entity.UserRecruitEntity;
import com.A01.sys.service.UserRecruitService;


@Service("userRecruitService")
public class UserRecruitServiceImpl extends ServiceImpl<UserRecruitDao, UserRecruitEntity> implements UserRecruitService {
    @Autowired
    private UserService userService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = (String) params.get("name");
        String idNumber = (String) params.get("idNumber");
        UserEntity user = ContextHolderUtils.getUser();
        List<UserEntity> userEntityList = userService.selectList(new EntityWrapper<UserEntity>()//通过求职者姓名进行模糊查询
                .like(StringUtils.isNotBlank(name), "chinese_name", name));
        if (CollectionUtils.isEmpty(userEntityList)) {//安全检查用户实体是否在空
            return new PageUtils(new Page<>());
        }
        //显示求职者-招聘信息
        List<Long> userIds = userEntityList.stream().map(UserEntity::getUserId).collect(Collectors.toList());
        EntityWrapper<UserRecruitEntity> ew = new EntityWrapper<>();
        ew.eq("company_id",user.getCompanyId());
        ew.in("user_id",userIds);
        Page<UserRecruitEntity> page = this.selectPage(
                new Query<UserRecruitEntity>(params).getPage(),
                ew
        );
        return new PageUtils(page);
    }

}
